import theme from '@/static/styles/theme.scss'
import { getRoleList, getCommonSetting } from '@/network/api'
const config = {
  state: {
    theme: theme,
    roleList: [
      {
        desc: '您好，我是Min，一位全能的人工智能助手，您可以向我提问，但请注意不要涉及任何违法违规政治敏感等问题，我们将会保留追究责任的权利。',
        id: -1,
        img: 'https://img.js.design/assets/smartFill/img312164da746310.jpg',
        is_vip: 0,
        name: 'Min',
        order: 0,
        role: 'system',
      },
    ],
    setting: {},
  },
  mutations: {
    setRoleList(state, data) {
      state.roleList = data
    },
    setSetting(state, data) {
      state.setting = data
    },
  },
  actions: {
    async setRoleList({ commit }) {
      const cache = uni.getStorageSync('roleList')
      if (cache) {
        commit('setRoleList', cache)
      }
      const res = await getRoleList()
      if (JSON.stringify(res) !== JSON.stringify(cache)) {
        uni.setStorageSync('roleList', res)
        commit('setRoleList', res)
      }
    },
    async getSetting({ commit }) {
      const cache = uni.getStorageSync('setting')
      if (cache) {
        commit('setSetting', cache)
      }
      const res = await getCommonSetting()
      if (JSON.stringify(res) !== JSON.stringify(cache)) {
        uni.setStorageSync('setting', res)
        commit('setSetting', res)
      }
    },
  },
}

export default config
